package casedemo;

import java.util.Random;

public class Test02 {

    public static void main(String[] args) {
        //todo：验证码
        System.out.println("4位验证码："+createCode(4));
        System.out.println("6位验证码："+createCode(6));
    }

    public static String createCode(int num){

        //1.字符串变量
        String code= "";
        Random r = new Random();
        for (int i =0;i<num;i++){
           int type= r.nextInt(3);

           switch (type){
               case 0:
                   int n =r.nextInt(10);
                   code+=n;
                   //System.out.println(code);
                   break;
               case 1:
                   char c1=(char)( r.nextInt(26)+65);
                   code +=c1;
                   //System.out.println(code);
                   break;
               case 2:
                   char c2=(char) (r.nextInt(26)+97);
                   code+=c2;
                   break;
           }
        }
        return code;
    }

}
